package behavioral.pattern.template.jdbc;



import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Autor: yuanyongan
 * @Description:
 * @Date 2023/1/9 17:01
 */
public abstract class JdbcTemplateImpl {
    public final Object execute(String sql) throws SQLException {

        // 获取链接
        Connection con = getConnection();
        Statement stmt = null;

        // 获取sql语句
        assert con != null;
        stmt = con.createStatement();
        // 执行sql语句
        ResultSet rs = stmt.executeQuery(sql);

        return doInStatement(rs);
    }

    abstract Object doInStatement(ResultSet rs);

    private Connection getConnection() {
        return null;
    }
}
